﻿/*创建人：盛金龙
 * 用途：项目基本信息
 * 时间：2012-02-08 周三
 */
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
using EnvironmentManagerSystem.BLL;
using EnvironmentManagerSystem.MODE;
using EnvironmentManagerSystem.Utility;
using AjaxPro;
using System.IO;
using System.Text;
using System.Drawing;
namespace EnvironmentManagerSystem.HuanJing
{
    public partial class HuanJing_Tabthree : System.Web.UI.Page
    {
        //窗体加载事件
        protected void Page_Load(object sender, EventArgs e)
        {
            AjaxPro.Utility.RegisterTypeForAjax(typeof(EnvironmentManagerSystem.HuanJing.HuanJing_Tabthree));
            //是否首次加载
            if (StfInfo.ReSession()) return; if (!IsPostBack)
            {

                DataBing();
                //正常
                if (Session["pjName"] != null && !Session["pjName"].ToString().Equals("") && Session["edit"] == null)
                {
                    check();
                    //btnsav.Disabled = true;
                    //btnsub.Disabled = true;
                    btn1.Enabled = false;
                    btn2.Enabled = false;

                }
                //添加
                else if (Session["pjName"].ToString().Equals("") && Session["edit"] == null)
                {
                    checka();
                    clear();
                    //btnsav.Disabled = false;
                    //btnsub.Disabled = false;
                    btn1.Enabled = true;
                    btn2.Enabled = true;
                    Js(Session["userid"].ToString());
                }
                //编辑
                else if (Session["edit"] != null && Session["edit"].ToString().Equals(""))
                {
                    Session["edit"] = null;
                    checkae();
                    tbs001_developprojectbasicinfo_ProjectName.Enabled = false;
                    //btnsav.Disabled = false;
                    //btnsub.Disabled = false;
                    btn1.Enabled = true;
                    btn2.Enabled = true;
                }
                //BindDevelopState();
                tbs001_developprojectbasicinfo_r4.Checked = true;
                tbs001_developprojectbasicinfo_r1.Checked = true;
            }

            #region 报告书/表
            if (tbs001_developprojectbasicinfo_r4.Checked == true)
            {
                rbtn = 1;
            }
            if (tbs001_developprojectbasicinfo_r5.Checked == true)
            {
                rbtn = 0;
            }
            if (tbs001_developprojectbasicinfo_r6.Checked == true)
            {
                rbtn = 0;
            }
            Session["rd"] = rbtn;
            Session["tb"] = tbs001_developprojectbasicinfo_Investment.Text;
            #endregion

        }
        protected int rbtn;

        #region 权限验证
        public void check()
        {
            try
            {
                for (int i = 0; i < this.Form.Controls.Count; i++)
                {
                    if (this.Form.Controls[i] is TextBox)
                    {
                        (this.Form.Controls[i] as TextBox).ReadOnly = true;
                    }
                    else if (this.Form.Controls[i] is DropDownList)
                    {
                        (this.Form.Controls[i] as DropDownList).Enabled = false;
                    }
                    else if (this.Form.Controls[i] is UpdatePanel)
                    {
                        for (int ii = 0; ii < (this.Form.Controls[i] as UpdatePanel).Controls[0].Controls.Count; ii++)
                        {
                            if ((this.Form.Controls[i] as UpdatePanel).Controls[0].Controls[ii] is TextBox)
                            {
                                ((this.Form.Controls[i] as UpdatePanel).Controls[0].Controls[ii] as TextBox).ReadOnly = true;
                            }
                            else if ((this.Form.Controls[i] as UpdatePanel).Controls[0].Controls[ii] is DropDownList)
                            {
                                ((this.Form.Controls[i] as UpdatePanel).Controls[0].Controls[ii] as DropDownList).Enabled = false;
                            }
                        }
                    }
                }
            }
            catch { }
        }
        #endregion

        #region 清空
        public void clear()
        {
            try
            {
                for (int i = 0; i < this.Form.Controls.Count; i++)
                {
                    if (this.Form.Controls[i] is TextBox)
                    {
                        (this.Form.Controls[i] as TextBox).Text = "";
                    }
                    else if (this.Form.Controls[i] is Label)
                    {
                        (this.Form.Controls[i] as Label).Text = "";
                    }
                    else if (this.Form.Controls[i] is DropDownList)
                    {
                        (this.Form.Controls[i] as DropDownList).SelectedIndex = 0;
                    }
                    else if (this.Form.Controls[i] is UpdatePanel)
                    {
                        for (int ii = 0; ii < (this.Form.Controls[i] as UpdatePanel).Controls[0].Controls.Count; ii++)
                        {
                            if ((this.Form.Controls[i] as UpdatePanel).Controls[0].Controls[ii] is TextBox)
                            {
                                ((this.Form.Controls[i] as UpdatePanel).Controls[0].Controls[ii] as TextBox).Text = "";
                            }
                            else if ((this.Form.Controls[i] as UpdatePanel).Controls[0].Controls[ii] is Label)
                            {
                                ((this.Form.Controls[i] as UpdatePanel).Controls[0].Controls[ii] as Label).Text = "";
                            }
                            else if ((this.Form.Controls[i] as UpdatePanel).Controls[0].Controls[ii] is DropDownList)
                            {
                                ((this.Form.Controls[i] as UpdatePanel).Controls[0].Controls[ii] as DropDownList).SelectedIndex = 0;
                            }
                        }
                    }
                }
            }
            catch { }
        }
        #endregion

        #region 权限验证
        public void checka()
        {
            try
            {
                for (int i = 0; i < this.Form.Controls.Count; i++)
                {
                    if (this.Form.Controls[i] is TextBox)
                    {
                        (this.Form.Controls[i] as TextBox).ReadOnly = false;
                        (this.Form.Controls[i] as TextBox).Attributes.Add("a", "true");
                    }
                    else if (this.Form.Controls[i] is RadioButton)
                    {
                        (this.Form.Controls[i] as RadioButton).Enabled = true;
                        (this.Form.Controls[i] as RadioButton).Checked = false;
                        (this.Form.Controls[i] as RadioButton).Attributes.Add("a", "true");
                        if ((this.Form.Controls[i] as RadioButton).ID.IndexOf("tbs001_developprojectbasicinfo") >= 0 || (this.Form.Controls[i] as RadioButton).ID.IndexOf("tbs001_developprojectbasicinfo") >= 0)
                        {
                            (this.Form.Controls[i] as RadioButton).Attributes.Add("onclick", "Connection.PjTest(this);");
                        }
                    }
                    else if (this.Form.Controls[i] is DropDownList)
                    {
                        (this.Form.Controls[i] as DropDownList).Enabled = true;
                    }
                    else if (this.Form.Controls[i] is UpdatePanel)
                    {
                        for (int ii = 0; ii < (this.Form.Controls[i] as UpdatePanel).Controls[0].Controls.Count; ii++)
                        {
                            if ((this.Form.Controls[i] as UpdatePanel).Controls[0].Controls[ii] is TextBox)
                            {
                                ((this.Form.Controls[i] as UpdatePanel).Controls[0].Controls[ii] as TextBox).ReadOnly = false;
                                ((this.Form.Controls[i] as UpdatePanel).Controls[0].Controls[ii] as TextBox).Attributes.Add("a", "true");
                            }
                            else if ((this.Form.Controls[i] as UpdatePanel).Controls[0].Controls[ii] is RadioButton)
                            {
                                ((this.Form.Controls[i] as UpdatePanel).Controls[0].Controls[ii] as RadioButton).Enabled = true;
                                ((this.Form.Controls[i] as UpdatePanel).Controls[0].Controls[ii] as RadioButton).Checked = false;
                                ((this.Form.Controls[i] as UpdatePanel).Controls[0].Controls[ii] as RadioButton).Attributes.Add("a", "true");
                                if (((this.Form.Controls[i] as UpdatePanel).Controls[0].Controls[ii] as RadioButton).ID.IndexOf("tbs001_developprojectbasicinfo") >= 0 || ((this.Form.Controls[i] as UpdatePanel).Controls[0].Controls[ii] as RadioButton).ID.IndexOf("tbs001_developprojectbasicinfo") >= 0)
                                {
                                    ((this.Form.Controls[i] as UpdatePanel).Controls[0].Controls[ii] as RadioButton).Attributes.Add("onclick", "Connection.PjTest(this);");
                                }
                            }
                            else if ((this.Form.Controls[i] as UpdatePanel).Controls[0].Controls[ii] is DropDownList)
                            {
                                ((this.Form.Controls[i] as UpdatePanel).Controls[0].Controls[ii] as DropDownList).Enabled = true;
                            }
                        }
                    }
                }
            }
            catch { }
        }
        #endregion

        #region 编辑权限验证
        public void checkae()
        {
            try
            {
                for (int i = 0; i < this.Form.Controls.Count; i++)
                {
                    if (this.Form.Controls[i] is TextBox)
                    {
                        (this.Form.Controls[i] as TextBox).Attributes.Add("a", "true");
                    }
                    else if (this.Form.Controls[i] is RadioButton)
                    {
                        (this.Form.Controls[i] as RadioButton).Enabled = true;
                        (this.Form.Controls[i] as RadioButton).Attributes.Add("a", "true");
                        if ((this.Form.Controls[i] as RadioButton).ID.IndexOf("tbs001_developprojectbasicinfo") >= 0 || (this.Form.Controls[i] as RadioButton).ID.IndexOf("tbs001_developprojectbasicinfo") >= 0)
                        {
                            (this.Form.Controls[i] as RadioButton).Attributes.Add("onclick", "Connection.PjTest(this);");
                        }
                    }
                    else if (this.Form.Controls[i] is UpdatePanel)
                    {
                        for (int ii = 0; ii < (this.Form.Controls[i] as UpdatePanel).Controls[0].Controls.Count; ii++)
                        {
                            if ((this.Form.Controls[i] as UpdatePanel).Controls[0].Controls[ii] is TextBox)
                            {
                                ((this.Form.Controls[i] as UpdatePanel).Controls[0].Controls[ii] as TextBox).Attributes.Add("a", "true");
                            }
                            else if ((this.Form.Controls[i] as UpdatePanel).Controls[0].Controls[ii] is RadioButton)
                            {
                                ((this.Form.Controls[i] as UpdatePanel).Controls[0].Controls[ii] as RadioButton).Enabled = true;
                                ((this.Form.Controls[i] as UpdatePanel).Controls[0].Controls[ii] as RadioButton).Attributes.Add("a", "true");
                                if (((this.Form.Controls[i] as UpdatePanel).Controls[0].Controls[ii] as RadioButton).ID.IndexOf("tbs001_developprojectbasicinfo") >= 0 || ((this.Form.Controls[i] as UpdatePanel).Controls[0].Controls[ii] as RadioButton).ID.IndexOf("tbs001_developprojectbasicinfo") >= 0)
                                {
                                    ((this.Form.Controls[i] as UpdatePanel).Controls[0].Controls[ii] as RadioButton).Attributes.Add("onclick", "Connection.PjTest(this);");
                                }
                            }
                        }
                    }
                }
            }
            catch { }
        }
        #endregion

        #region 进行数据绑定
        public void DataBing()
        {
            try
            {
                #region DropDownList绑定
                //环评单位
                DataTable Collection = EnvironmentManagerSystem.BLL.ConstructionUnit.GetList();
                DropDownList2.DataSource = Collection;
                DropDownList2.DataBind();
                DropDownList2.Items.Insert(0, new ListItem("请选择", "0"));
                if (Session["pjName"].ToString() != "")
                {
                    DataTable dt = HuanPingService.GetProjects();
                    if (dt.Rows.Count == 0)
                        return;
                    if (dt.Rows[0]["hp"].ToString().Trim() != "")
                        DropDownList2.SelectedValue = dt.Rows[0]["hp"].ToString();
                }
                //负责人
                DbFz(EnvironmentManagerSystem.BLL.ConstructionUnit.GetRen());
                //行业类别1
                DataTable ccc = EnvironmentManagerSystem.BLL.ConstructionUnit.Gethylb("14", "%");
                IndustryType1.DataSource = ccc;
                IndustryType1.DataBind();
                IndustryType1.Items.Insert(0, new ListItem("请选择", "0%"));
                //环统类别
                DataTable aaaaaa = EnvironmentManagerSystem.BLL.ConstructionUnit.Gethylb("75");
                tbs001_developprojectbasicinfo_ESIndustryType.DataSource = aaaaaa;
                tbs001_developprojectbasicinfo_ESIndustryType.DataBind();
                tbs001_developprojectbasicinfo_ESIndustryType.Items.Insert(0, new ListItem("请选择", "0"));
                //环评类别
                DataTable cccccc = EnvironmentManagerSystem.BLL.ConstructionUnit.Gethylb("7");
                tbs001_developprojectbasicinfo_huanpingleibie.DataSource = cccccc;
                tbs001_developprojectbasicinfo_huanpingleibie.DataBind();
                tbs001_developprojectbasicinfo_huanpingleibie.Items.Insert(0, new ListItem("请选择", "0"));
                //地区代码1
                DataTable aaaaaacc = EnvironmentManagerSystem.BLL.ConstructionUnit.Gethylb("30", "%00");
                diqu1.DataSource = aaaaaacc;
                diqu1.DataBind();
                diqu1.Items.Insert(0, new ListItem("请选择", "0"));
                #endregion

                Hashtable list = EnvironmentManagerSystem.BLL.HuanJing.GetConstructionunit(Session["pjName"] != null ? Session["pjName"].ToString() : "");
                if (list != null && list.Count > 0)
                {
                    //string DevelopState = list["tbs001_developprojectbasicinfo_DevelopState"].ToString();
                    //Session["DevelopState"] = DevelopState;

                    #region 单选按钮/复选按钮
                    if (list["tbs001_developprojectbasicinfo_DevelopState"].ToString().Equals("新建"))
                    {
                        tbs001_developprojectbasicinfo_r1.Checked = true;
                        tbs001_developprojectbasicinfo_r2.Checked = false;
                        tbs001_developprojectbasicinfo_r2.Enabled = false;
                        tbs001_developprojectbasicinfo_r3.Checked = false;
                        tbs001_developprojectbasicinfo_r3.Enabled = false;
                    }
                    else if (list["tbs001_developprojectbasicinfo_DevelopState"].ToString().Equals("改扩建"))
                    {
                        tbs001_developprojectbasicinfo_r2.Checked = true;
                        tbs001_developprojectbasicinfo_r1.Checked = false;
                        tbs001_developprojectbasicinfo_r1.Enabled = false;
                        tbs001_developprojectbasicinfo_r3.Checked = false;
                        tbs001_developprojectbasicinfo_r3.Enabled = false;
                    }
                    //if (list["tbs001_developprojectbasicinfo_DevelopState"].ToString().Equals("技术改造"))
                    else
                    {
                        tbs001_developprojectbasicinfo_r3.Checked = true;
                        tbs001_developprojectbasicinfo_r1.Checked = false;
                        tbs001_developprojectbasicinfo_r1.Enabled = false;
                        tbs001_developprojectbasicinfo_r2.Checked = false;
                        tbs001_developprojectbasicinfo_r2.Enabled = false;
                    }
                    if (list["tbs001_developprojectbasicinfo_BiangengTuihuichongbao"].ToString().Equals("变更"))
                    {
                        CheckBox1.Checked = true;
                        CheckBox2.Checked = false;
                        CheckBox2.Enabled = false;
                    }
                    else if (list["tbs001_developprojectbasicinfo_BiangengTuihuichongbao"].ToString().Equals("退回重报"))
                    {
                        CheckBox2.Checked = true;
                        CheckBox1.Checked = false;
                        CheckBox1.Enabled = false;
                    }
                    else if (list["tbs001_developprojectbasicinfo_BiangengTuihuichongbao"].ToString().Equals("变更,退回重报"))
                    {
                        CheckBox1.Checked = true;
                        CheckBox2.Checked = true;
                    }
                    #endregion

                    #region 报告书/一般报告表/特殊报告表
                    if (list["tbs001_developprojectbasicinfo_Report"].ToString().Equals("报告书"))
                    {
                        tbs001_developprojectbasicinfo_r4.Checked = true;
                        tbs001_developprojectbasicinfo_r5.Checked = false;
                        tbs001_developprojectbasicinfo_r6.Checked = false;
                        tbs001_developprojectbasicinfo_r5.Enabled = false;
                        tbs001_developprojectbasicinfo_r6.Enabled = false;
                    }
                    else if (list["tbs001_developprojectbasicinfo_Report"].ToString().Equals("一般报告表"))
                    {
                        tbs001_developprojectbasicinfo_r5.Checked = true;
                        tbs001_developprojectbasicinfo_r4.Checked = false;
                        tbs001_developprojectbasicinfo_r6.Checked = false;
                        tbs001_developprojectbasicinfo_r4.Enabled = false;
                        tbs001_developprojectbasicinfo_r6.Enabled = false;
                    }
                    else
                    {
                        tbs001_developprojectbasicinfo_r6.Checked = true;
                        tbs001_developprojectbasicinfo_r4.Checked = false;
                        tbs001_developprojectbasicinfo_r5.Checked = false;
                        tbs001_developprojectbasicinfo_r4.Enabled = false;
                        tbs001_developprojectbasicinfo_r5.Enabled = false;
                        BindHuanPing("特殊报告表");
                    }
                    #endregion

                    #region 建设项目基本信息
                    foreach (DictionaryEntry de in list)
                    {
                        if (this.frm.FindControl(de.Key.ToString()) != null && (this.frm.FindControl(de.Key.ToString()) is TextBox))
                        {
                            ((TextBox)this.frm.FindControl(de.Key.ToString())).Text = de.Value.ToString();
                        }
                        else if ((this.frm.FindControl(de.Key.ToString()) is DropDownList))
                        {
                            if (de.Value != null && de.Value.ToString() != string.Empty)
                                ((DropDownList)this.frm.FindControl(de.Key.ToString())).SelectedValue = de.Value.ToString();
                        }
                        else if (de.Key.ToString().Equals("tbs001_developprojectbasicinfo_AddressCode1"))
                        {
                            try
                            {
                                string[] st = de.Value.ToString().Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                                diqu1.SelectedValue = st[0];
                                diqu1_SelectedIndexChanged(null, null);
                                diqu2.SelectedValue = st[1];
                            }
                            catch { }
                        }
                    }
                    #region
                    try
                    {
                        IndustryType1.SelectedValue = list["tbs001_developprojectbasicinfo_IndustryType1"].ToString();
                        tbs001_developprojectbasicinfo_IndustryType1_SelectedIndexChanged(null, null);
                    }
                    catch { }
                    try
                    {
                        IndustryType2.SelectedValue = list["tbs001_developprojectbasicinfo_IndustryType2"].ToString();
                        tbs001_developprojectbasicinfo_IndustryType2_SelectedIndexChanged(null, null);
                    }
                    catch { }
                    try
                    {
                        IndustryType3.SelectedValue = list["tbs001_developprojectbasicinfo_IndustryType3"].ToString();
                    }
                    catch { }
                    #endregion

                    #endregion

                    #region 建设单位基本信息
                    Js(list["tbs001_developprojectbasicinfo_js"].ToString());
                    #endregion

                    #region 环评单位信息
                    Hashtable listThree = EnvironmentManagerSystem.BLL.HuanJing.GetConstructionunitThree(list["tbs001_developprojectbasicinfo_hp"].ToString());
                    if (listThree != null)
                    {
                        foreach (DictionaryEntry de in listThree)
                        {
                            if (this.frm.FindControl(de.Key.ToString()) != null && (this.frm.FindControl(de.Key.ToString()) is Label))
                            {
                                ((Label)this.frm.FindControl(de.Key.ToString())).Text = de.Value.ToString();
                            }
                        }
                    }
                    #endregion
                }
            }
            catch
            {
                Jscript.Alert("数据异常", this.Page);
            }
        }
        #endregion

        #region BindHuanPing
        private void BindHuanPing(string CValue)
        {
            tbs001_developprojectbasicinfo_huanpingleibie.Items.Clear();
            DataTable dt = null;
            if (CValue == "特殊报告表")
                dt = EnvironmentManagerSystem.BLL.ConstructionUnit.Gethylb();
            else
                dt = EnvironmentManagerSystem.BLL.ConstructionUnit.Gethylb("7");
            tbs001_developprojectbasicinfo_huanpingleibie.DataSource = dt;
            tbs001_developprojectbasicinfo_huanpingleibie.DataBind();
            tbs001_developprojectbasicinfo_huanpingleibie.Items.Insert(0, new ListItem("请选择", "0"));
        }
        #endregion

        /// <summary>
        /// 编辑数据库
        /// </summary>
        [AjaxPro.AjaxMethod(HttpSessionStateRequirement.ReadWrite)]
        public bool EditTable(string CName, string CValue, string log, string str)
        {
            try
            {
                bool bo = false;
                if (CName == "jingdu" || CName == "weidu")
                {
                    if (OfficeHelper.Regex(CValue))
                    {
                        if (CValue.Contains('\''))
                            CValue = CValue.Split('\'')[0] + "\'\'" + CValue.Split('\'')[1];
                        bo = EnvironmentManagerSystem.BLL.HuanJing.EditTableXM(CName, CValue, log, str);
                    }
                }
                else
                    bo = EnvironmentManagerSystem.BLL.HuanJing.EditTableXM(CName, CValue, log, str);
                if (CName.Equals("Report"))
                {
                    if (CValue.Equals("报告书")) Session["rd"] = 1;
                    else Session["rd"] = 0;
                }
                if (bo) Session["pjName"] = str;
                else Session["pjName"] = "";
                return bo;
            }
            catch { return true; }
        }

        /// <summary>
        /// 编辑数据库
        /// </summary>
        [AjaxPro.AjaxMethod(HttpSessionStateRequirement.ReadWrite)]
        public void SelectList3Value(string id, string name, string str)
        {
            try
            {
                EnvironmentManagerSystem.BLL.ConstructionUnit.SetRen(id, name, str);
            }
            catch { }
        }

        /// <summary>
        /// 项目保存
        /// </summary>
        [AjaxPro.AjaxMethod(HttpSessionStateRequirement.ReadWrite)]
        public void DbSave(string name, string log)
        {
            try
            {
                EnvironmentManagerSystem.BLL.ConstructionUnit.SetStatus(name, log);
                //ddd();
            }
            catch { }
        }
        public void ddd()
        {
            string BiangengTuihuichongbao = "";
            string name = "";
            name = Session["pjName"].ToString();
            CheckBox1.Checked = true;
            EnvironmentManagerSystem.BLL.ConstructionUnit.bts(BiangengTuihuichongbao, name);
            //if (tbs001_developprojectbasicinfo_c7.Checked == true)
            //{
            //    BiangengTuihuichongbao = "变更";
            //}
            //else if (tbs001_developprojectbasicinfo_c8.Checked == true)
            //{
            //    BiangengTuihuichongbao = "退回重报";
            //}
            //else if (tbs001_developprojectbasicinfo_c8.Checked == true && tbs001_developprojectbasicinfo_c8.Checked == true)
            //{
            //    BiangengTuihuichongbao = "变更,退回重报";
            //}

        }
        #region 建设单位数据
        private void Js(string str)
        {
            #region 建设单位基本信息
            Hashtable listTwo = EnvironmentManagerSystem.BLL.HuanJing.GetConstructionunitTwo(str);
            if (listTwo != null)
            {
                foreach (DictionaryEntry de in listTwo)
                {
                    if (this.frm.FindControl(de.Key.ToString()) != null && (this.frm.FindControl(de.Key.ToString()) is Label))
                    {
                        ((Label)this.frm.FindControl(de.Key.ToString())).Text = de.Value.ToString();
                    }
                }
            }
            #endregion
        }
        #endregion

        #region 地区代码
        //地区代码1
        protected void diqu1_SelectedIndexChanged(object sender, EventArgs e)
        {
            diqu2.Items.Clear();
            //地区代码2
            DataTable dt = EnvironmentManagerSystem.BLL.ConstructionUnit.Gethylb("30", diqu1.Text.Substring(0, diqu1.Text.Length - 2) + "%");
            diqu2.DataSource = dt;
            diqu2.DataBind();
            diqu2_SelectedIndexChanged(sender, e);
        }

        //地区代码2
        protected void diqu2_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                if (!tbs001_developprojectbasicinfo_ProjectName.Text.Equals(""))
                {
                    EditTable("AddressCode1", diqu1.SelectedValue + "," + diqu2.SelectedValue, "false", tbs001_developprojectbasicinfo_ProjectName.Text);
                }
                else ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "alert", "alert('输入项目名称')", true);
            }
            catch { }
        }
        #endregion

        #region 行业负责人DropDownListBind
        private void DbFz(DataTable dt)
        {
            try
            {
                //项目负责人
                tbs001_developprojectbasicinfo_xiangmufuzheren.DataSource = dt;
                tbs001_developprojectbasicinfo_xiangmufuzheren.DataBind();
                tbs001_developprojectbasicinfo_xiangmufuzheren.Items.Insert(0, new ListItem("请选择", "0"));
            }
            catch { }
        }
        #endregion
        #region 全角半角转换
        /// <summary>
        /// 转全角的函数（SBC case）
        /// </summary>
        /// <param name="input">任意字符串</param>
        /// <returns>全角字符串</returns>
        /// </remarks>
        /// 全角空格为12288，半角空格为32
        /// 其他字符半角（33-126）与全角（65281-65374）的对应关系是：均相差65248
        /// </remarks>      
        public static string ToSBC(string input)
        {
            //半角转全角
            char[] c = input.ToCharArray();
            for (int i = 0; i < c.Length; i++)
            {
                if (c[i] == 32)
                {
                    c[i] = (char)12288;
                    continue;
                }
                if (c[i] < 127)
                    c[i] = (char)(c[i] + 65248);
            }
            return new string(c);
        }
        #endregion
        #region 项目名称
        protected void tbs001_developprojectbasicinfo_ProjectName_TextChanged(object sender, EventArgs e)
        {
            string pjName = this.tbs001_developprojectbasicinfo_ProjectName.Text.Trim();

            if (2 * pjName.Length == Encoding.Default.GetByteCount(pjName))
            {

                DataTable dt = HuanPingService.SelectPjName(pjName);
                if (dt != null && dt.Rows.Count > 0)
                {
                    lblTishi.Text = "项目名称已存在，请重新输入！";
                    tbs001_developprojectbasicinfo_ProjectName.Text = "";
                }
                else
                {
                    EditTable(tbs001_developprojectbasicinfo_ProjectName.ID.Substring(tbs001_developprojectbasicinfo_ProjectName.ID.LastIndexOf("_") + 1), tbs001_developprojectbasicinfo_ProjectName.Text.Trim(), "true", tbs001_developprojectbasicinfo_ProjectName.Text.Trim());
                    tbs001_developprojectbasicinfo_ProjectName.Enabled = false;
                    lblTishi.Text = "";
                }
            }
            else
            {
                char[] c = pjName.ToCharArray();
                for (int i = 0; i < c.Length; i++)
                {
                    if (c[i] == 32)
                    {
                        c[i] = (char)12288;
                        continue;
                    }
                    if (c[i] < 127)
                        c[i] = (char)(c[i] + 65248);
                }
                //return new string(c);
                string s = new string(c);
                Session["spj"] = s;
                string aaa = Session["spj"].ToString();
                DataTable dt = HuanPingService.SelectPjName(s);
                if (dt != null && dt.Rows.Count > 0)
                {
                    lblTishi.Text = "项目名称已存在，请重新输入！";
                    tbs001_developprojectbasicinfo_ProjectName.Text = "";
                }
                else
                {
                    //EditTable(tbs001_developprojectbasicinfo_ProjectName.ID.Substring(tbs001_developprojectbasicinfo_ProjectName.ID.LastIndexOf("_") + 1), tbs001_developprojectbasicinfo_ProjectName.Text.Trim(), "true", tbs001_developprojectbasicinfo_ProjectName.Text.Trim());
                    EditTable(tbs001_developprojectbasicinfo_ProjectName.ID.Substring(tbs001_developprojectbasicinfo_ProjectName.ID.LastIndexOf("_") + 1), s, "true", s);
                    tbs001_developprojectbasicinfo_ProjectName.Enabled = false;
                    lblTishi.Text = "";
                }
            }
            //string pjName = this.tbs001_developprojectbasicinfo_ProjectName.Text.Trim();
            //DataTable dt = HuanPingService.SelectPjName(pjName);
            //if (dt != null && dt.Rows.Count > 0)
            //{
            //    lblTishi.Text = "项目名称已存在，请重新输入！";
            //}
            //else
            //{
            //    EditTable(tbs001_developprojectbasicinfo_ProjectName.ID.Substring(tbs001_developprojectbasicinfo_ProjectName.ID.LastIndexOf("_") + 1), tbs001_developprojectbasicinfo_ProjectName.Text.Trim(), "true", tbs001_developprojectbasicinfo_ProjectName.Text.Trim());
            //    tbs001_developprojectbasicinfo_ProjectName.Enabled = false;
            //    lblTishi.Text = "";
            //}
        }
        #endregion

        #region 环评单位信息
        protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (Session["rd"] != null && Session["rd"].ToString().Equals("1"))
            {
                DataTable dd = EnvironmentManagerSystem.BLL.ConstructionUnit.GetRenWhere(DropDownList2.SelectedValue, tbs001_developprojectbasicinfo_huanpingleibie.SelectedValue);
                DbFz(dd);
            }
            else DbFz(EnvironmentManagerSystem.BLL.ConstructionUnit.GetRens(DropDownList2.SelectedValue));

            EvaluationUnitData ev = EnvironmentManagerSystem.BLL.HuanJing.GetConstructionunitThree(DropDownList2.SelectedValue, tbs001_developprojectbasicinfo_ProjectName.Text);
            tbs001_evaluationunit_UnitName.Text = ev.UnitName;
            tbs001_evaluationunit_Phone.Text = ev.Phone;
            tbs001_evaluationunit_ZipCode.Text = ev.ZipCode;
            tbs001_evaluationunit_Address.Text = ev.Address;
            tbs001_evaluationunit_CertificateNo.Text = ev.CertificateNo;
        }
        #endregion

        #region 行业类别
        //行业类别
        protected void tbs001_developprojectbasicinfo_IndustryType1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (!tbs001_developprojectbasicinfo_ProjectName.Text.Equals(""))
            {
                //行业类别2
                IndustryType2.DataSource = EnvironmentManagerSystem.BLL.ConstructionUnit.Gethylb("24", IndustryType1.SelectedValue + "%");
                IndustryType2.DataBind();
                tbs001_developprojectbasicinfo_IndustryType2_SelectedIndexChanged(sender, e);
            }
            else ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "alert", "alert('输入项目名称')", true);
        }
        protected void tbs001_developprojectbasicinfo_IndustryType2_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (!tbs001_developprojectbasicinfo_ProjectName.Text.Equals(""))
            {
                //行业类别3
                IndustryType3.DataSource = EnvironmentManagerSystem.BLL.ConstructionUnit.Gethylb("25", IndustryType2.SelectedValue + "%");
                IndustryType3.DataBind();
                tbs001_developprojectbasicinfo_IndustryType3_SelectedIndexChanged(sender, e);
            }
            else ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "alert", "alert('输入项目名称')", true);
        }
        protected void tbs001_developprojectbasicinfo_IndustryType3_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (!tbs001_developprojectbasicinfo_ProjectName.Text.Equals(""))
            {
                SelectList3Value(IndustryType1.SelectedValue, tbs001_developprojectbasicinfo_ProjectName.Text, "1");
                SelectList3Value(IndustryType2.SelectedValue, tbs001_developprojectbasicinfo_ProjectName.Text, "2");
                SelectList3Value(IndustryType3.SelectedValue, tbs001_developprojectbasicinfo_ProjectName.Text, "3");
            }
            else ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "alert", "alert('输入项目名称')", true);
        }
        #endregion

        #region CheckedChanged
        protected void tbs001_developprojectbasicinfo_r4_CheckedChanged(object sender, EventArgs e)
        {
            BindHuanPing("");
            EditTable("Report", tbs001_developprojectbasicinfo_r4.Text, "false", tbs001_developprojectbasicinfo_ProjectName.Text);
        }

        protected void tbs001_developprojectbasicinfo_r5_CheckedChanged(object sender, EventArgs e)
        {
            BindHuanPing("");
            EditTable("Report", tbs001_developprojectbasicinfo_r5.Text, "false", tbs001_developprojectbasicinfo_ProjectName.Text);
        }

        protected void tbs001_developprojectbasicinfo_r6_CheckedChanged(object sender, EventArgs e)
        {
            BindHuanPing("特殊报告表");
            EditTable("Report", tbs001_developprojectbasicinfo_r6.Text, "false", tbs001_developprojectbasicinfo_ProjectName.Text);
        }
        #endregion

        #region NewMethod
        private DevelopprojectbasicinfoData NewMethod()
        {
            DevelopprojectbasicinfoData dbd = new DevelopprojectbasicinfoData();
            string ses = this.tbs001_developprojectbasicinfo_ProjectName.Text.Trim();

            if (2 * ses.Length == Encoding.Default.GetByteCount(ses))
            {
                dbd.ProjectName = this.tbs001_developprojectbasicinfo_ProjectName.Text.Trim();//项目名称
            }
            else
            {
                char[] cc = ses.ToCharArray();
                for (int i = 0; i < cc.Length; i++)
                {
                    if (cc[i] == 32)
                    {
                        cc[i] = (char)12288;
                        continue;
                    }
                    if (cc[i] < 127)
                        cc[i] = (char)(cc[i] + 65248);
                }
                string ss = new string(cc);
                dbd.ProjectName = ss;
            }
            #region 建设项目基本信息
            //dbd.ProjectName = this.tbs001_developprojectbasicinfo_ProjectName.Text.Trim();//项目名称
            //dbd.ProjectName = this.Session["spj"].ToString();
            dbd.ProjectAddress = this.tbs001_developprojectbasicinfo_ProjectAddress.Text.Trim();//建设地点
            dbd.ProjectPerson = this.tbs001_developprojectbasicinfo_ProjectPerson.Text.Trim();//项目联系人
            dbd.Mobil = this.tbs001_developprojectbasicinfo_Mobil.Text.Trim();//联系人电话
            dbd.EnvironmentalInvestmentProportion = this.tbs001_developprojectbasicinfo_EnvironmentalInvestmentProportion.Text.Trim();//环保投资(万元)
            dbd.Investment = this.tbs001_developprojectbasicinfo_Investment.Text.Trim();//总投资(万元)
            dbd.GPSE = this.tbs001_developprojectbasicinfo_GPSE.Text.Trim();//所占比例
            dbd.AddressCode1 = this.diqu1.SelectedValue + "," + diqu2.SelectedValue;//地区代码
            if (tbs001_developprojectbasicinfo_r4.Checked == true)//报告书/表
                dbd.Report = "报告书";
            if (tbs001_developprojectbasicinfo_r5.Checked == true)
                dbd.Report = "一般报告表";
            if (tbs001_developprojectbasicinfo_r6.Checked == true)
                dbd.Report = "特殊报告表";
            dbd.jingdu = this.tbs001_developprojectbasicinfo_jingdu.Text.Trim();//经度
            dbd.weidu = this.tbs001_developprojectbasicinfo_weidu.Text.Trim();//纬度           
            dbd.pingjiajingfei = this.tbs001_developprojectbasicinfo_pingjiajingfei.Text.Trim();//评价经费(万元)
            dbd.ESIndustryType = this.tbs001_developprojectbasicinfo_ESIndustryType.SelectedValue;//环统类别
            dbd.huanpingleibie = this.tbs001_developprojectbasicinfo_huanpingleibie.SelectedValue;//环评类别
            if (tbs001_developprojectbasicinfo_r1.Checked == true)//新建/改扩建/技术改造
                dbd.DevelopState = "新建";
            if (tbs001_developprojectbasicinfo_r2.Checked == true)
                dbd.DevelopState = "改扩建";
            if (tbs001_developprojectbasicinfo_r3.Checked == true)
                dbd.DevelopState = "技术改造";
            if (CheckBox1.Checked == true)//变更/退回重报
                dbd.BiangengTuihuichongbao = "变更";
            if (CheckBox2.Checked == true)
                dbd.BiangengTuihuichongbao = "退回重报";
            if (CheckBox1.Checked == true && CheckBox2.Checked == true)
                dbd.BiangengTuihuichongbao = "变更,退回重报";
            dbd.IndustryType1 = this.IndustryType1.SelectedValue;//行业类别一
            dbd.IndustryType2 = this.IndustryType2.SelectedValue;//行业类别二
            dbd.IndustryType3 = this.IndustryType3.SelectedValue;//行业类别三
            dbd.EIAIndustryType = this.tbs001_developprojectbasicinfo_EIAIndustryType.Text.Trim();//建设内容及规模
            dbd.xmmsxx = this.tbs001_developprojectbasicinfo_xmmsxx.Text.Trim();//项目描述信息
            #endregion

            #region 建设单位基本信息
            int js = Convert.ToInt32(Session["userid"]);
            dbd.js = js;
            #endregion

            #region 环评单位基本信息
            if (Convert.ToInt32(this.DropDownList2.SelectedValue) != 0)
                dbd.hp = Convert.ToInt32(this.DropDownList2.SelectedValue);//环评单位信息
            if (Convert.ToInt32(this.tbs001_developprojectbasicinfo_xiangmufuzheren.SelectedValue) != 0)
                dbd.xiangmufuzheren = Convert.ToInt32(this.tbs001_developprojectbasicinfo_xiangmufuzheren.SelectedValue);//项目负责人
            dbd.hplianxiren = this.tbs001_developprojectbasicinfo_hplianxiren.Text.Trim();//环评单位联系人
            dbd.dianhua = this.tbs001_developprojectbasicinfo_dianhua.Text.Trim();//联系人电话
            #endregion
            return dbd;
        }
        #endregion

        #region btn1_Click保存(x)
        protected void btn1_Click(object sender, EventArgs e)
        {
            if (tbs001_developprojectbasicinfo_ProjectName.Text.Trim() == "")
            {
                Jscript.Alert("项目名称不能为空!", this);
            }
            else
            {
                DevelopprojectbasicinfoData dbd = NewMethod();
                if (XIANGMU.Updatedbd(dbd))
                    Jscript.Alert("操作成功！", this);
                else
                    Jscript.Alert("操作失败！", this);
            }

        }
        #endregion

        #region btn2_Click提交(x)
        protected void btn2_Click(object sender, EventArgs e)
        {

            if (Check1())
            {
                try
                {
                    DevelopprojectbasicinfoData dbd = NewMethod();
                    if (XIANGMU.UpdatedbdTiJiao(dbd))
                        Jscript.Alert("提交成功！", this);
                    else
                        Jscript.Alert("提交失败！", this);
                }
                catch { }
            }
        }
        #endregion

        #region Check()
        public Boolean Check1()
        {
            if (
                !tbs001_developprojectbasicinfo_ProjectName.Text.Trim().Equals("")//项目名称
                && !tbs001_developprojectbasicinfo_ProjectAddress.Text.Trim().Equals("")//建设地点
                && !tbs001_developprojectbasicinfo_ProjectPerson.Text.Trim().Equals("")//项目联系人
                && !tbs001_developprojectbasicinfo_Mobil.Text.Trim().Equals("")//联系人电话
                && !tbs001_developprojectbasicinfo_EnvironmentalInvestmentProportion.Text.Trim().Equals("")//环保投资
                && !tbs001_developprojectbasicinfo_Investment.Text.Trim().Equals("")//总投资
                && !tbs001_developprojectbasicinfo_GPSE.Text.Trim().Equals("")//所占比例
                && !diqu1.SelectedValue.Trim().Equals("0")//地区代码
                && !diqu2.SelectedValue.Trim().Equals("0")//地区代码
                //报告书表
                && !tbs001_developprojectbasicinfo_pingjiajingfei.Text.Trim().Equals("")//评价经费
                && !tbs001_developprojectbasicinfo_ESIndustryType.SelectedValue.Trim().Equals("0")//环统类别
                && !tbs001_developprojectbasicinfo_huanpingleibie.SelectedValue.Trim().Equals("0")//环评类别
                //建设性质
                && !IndustryType1.SelectedValue.Trim().Equals("0")//行业类别一
                && !IndustryType2.SelectedValue.Trim().Equals("0")//行业类别二
                && !IndustryType3.SelectedValue.Trim().Equals("0")//行业类别三
                && !tbs001_developprojectbasicinfo_EIAIndustryType.Text.Trim().Equals("")//建设内容及规模
                && !DropDownList2.SelectedValue.Trim().Equals("0")//环评单位信息
                && !tbs001_developprojectbasicinfo_xiangmufuzheren.SelectedValue.Trim().Equals("0")//项目负责人
                && !tbs001_developprojectbasicinfo_hplianxiren.Text.Trim().Equals("")//联系人
                && !tbs001_developprojectbasicinfo_dianhua.Text.Trim().Equals("")//联系人电话
                )
            {
                return true;
            }
            else
            {
                Jscript.Alert("信息填写不完整,请填写必填项！", this);
                return false;
            }
        }
        #endregion

        #region MyRegion
        protected void tbs001_developprojectbasicinfo_huanpingleibie_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (Session["rd"] != null && Session["rd"].ToString().Equals("1"))
            {
                DataTable dd = EnvironmentManagerSystem.BLL.ConstructionUnit.GetRenWhere(DropDownList2.SelectedValue, tbs001_developprojectbasicinfo_huanpingleibie.SelectedValue);
                DbFz(dd);
            }
            else DbFz(EnvironmentManagerSystem.BLL.ConstructionUnit.GetRens(DropDownList2.SelectedValue));

        }
        #endregion
    }
}          
